package com.stylefeng.guns.modular.stockmanagement.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.GoodsDamageList;
import com.stylefeng.guns.modular.stockmanagement.service.IGoodsDamageListService;

/**
 * 商品报损查询控制器
 *
 * @author LiuXin
 * @Date 2018-09-19 13:17:11
 */
@Controller
@RequestMapping("/goodsDamageList")
public class GoodsDamageListController extends BaseController {

    private String PREFIX = "/stockmanagement/goodsDamageList/";

    @Autowired
    private IGoodsDamageListService goodsDamageListService;

    /**
     * 跳转到商品报损查询首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "goodsDamageList.html";
    }

    /**
     * 跳转到添加商品报损查询
     */
    @RequestMapping("/goodsDamageList_add")
    public String goodsDamageListAdd() {
        return PREFIX + "goodsDamageList_add.html";
    }

    /**
     * 跳转到修改商品报损查询
     */
    @RequestMapping("/goodsDamageList_update/{goodsDamageListId}")
    public String goodsDamageListUpdate(@PathVariable Integer goodsDamageListId, Model model) {
        GoodsDamageList goodsDamageList = goodsDamageListService.selectById(goodsDamageListId);
        model.addAttribute("item",goodsDamageList);
        LogObjectHolder.me().set(goodsDamageList);
        return PREFIX + "goodsDamageList_edit.html";
    }

    /**
     * 获取商品报损查询列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return goodsDamageListService.selectList(null);
    }

    /**
     * 新增商品报损查询
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(GoodsDamageList goodsDamageList) {
        goodsDamageListService.insert(goodsDamageList);
        return SUCCESS_TIP;
    }

    /**
     * 删除商品报损查询
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer goodsDamageListId) {
        goodsDamageListService.deleteById(goodsDamageListId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商品报损查询
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(GoodsDamageList goodsDamageList) {
        goodsDamageListService.updateById(goodsDamageList);
        return SUCCESS_TIP;
    }

    /**
     * 商品报损查询详情
     */
    @RequestMapping(value = "/detail/{goodsDamageListId}")
    @ResponseBody
    public Object detail(@PathVariable("goodsDamageListId") Integer goodsDamageListId) {
        return goodsDamageListService.selectById(goodsDamageListId);
    }
}
